package com.yonyou.gmmc.service.wechatpush.event.handler;

import org.marketing.common.dto.EventDataDTO;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocol;
import org.marketing.common.event.BizEvent;
import org.marketing.common.event.EventMaintainChangedDTO;
import org.marketing.common.event.EventPointsChangedDTO;
import org.marketing.common.util.MapConverUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yonyou.gmmc.service.wechatpush.event.exception.PushException;
import com.yonyou.gmmc.service.wechatpush.event.service.MaintainAppointmentConfirmService;
import com.yonyou.gmmc.service.wechatpush.util.SpringUtil;

//养修预约确认提醒
public class MaintainAppointmentConfirmHandler extends AbstractEventHandle {

	private static Logger logger = LoggerFactory.getLogger(MaintainAppointmentConfirmHandler.class);
	
	private MaintainAppointmentConfirmService maintainAppointmentConfirmService;
	@Override
	protected String getHandleInfo() {
		return "处理养修预约确认提醒";
	}

	
	/**
	 * 主要进行数据转换
	 */
	@Override
	protected EventDataDTO preCheck(BizEvent event) {
		EventMaintainChangedDTO o = new EventMaintainChangedDTO();
		try {
			o = (EventMaintainChangedDTO) MapConverUtil.map2PO(event.getEventData(), o);
			logger.info(o.toString());
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			this.backInfo = "eventData中的业务数据不能识别：" + e.getMessage();
			throw new PushException(PushException.EVENT_CONVERT_FAILD,"eventData中的业务数据不能识别");
		}
		return o;
	}

	/**
	 * 模板推送处理的逻辑
	 */
	@Override
	protected boolean push(EventDataDTO eventData) throws PushException{
		maintainAppointmentConfirmService=(MaintainAppointmentConfirmService)SpringUtil.getBean("maintainAppointmentConfirmService");
		WeChatMessageProtocol t=maintainAppointmentConfirmService.getWXTemplate((EventMaintainChangedDTO)eventData);
		this.sendNotify(t);
		return true;
	}
}
